import Request from './request'

export default function Login(cb) {
  try {
    wx.login({
      success(res) {
        Request.get('/api/login', { code: res.code })
          .then((succ) => {
            Request.si = succ.data.si
            cb(succ)
          }).catch((err) => {
            throw new Error(err.msg || err.message)
          })
      }
    })
  } catch (err) {
    Request.get('/api/login', {code: 'APTX4869'})
      .then((succ) => {
        Request.si = succ.data.si
        console.log('cocos called', Request)
        cb(succ)
      })
  }
}